﻿using System;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using VerticalMenu.Utility;

namespace VerticalMenu
{
	public class CommandInfos
	{
		public string CmdName { get; set; }

		public string CmdText { get; set; }

		public string DllName { get; set; }

		public string ClassName { get; set; }

		public string ImageName { get; set; }

		public string Tooltip { get; set; }

		public string PanelName { get; set; }

		public CommandInfos()
		{
		}

		public CommandInfos(string cmdName, string cmdText, string dllName, string className, string imageName, string tooltip, string panelName)
		{
			this.CmdName = cmdName;
			this.CmdText = cmdText;
			this.DllName = dllName;
			this.ClassName = className;
			this.ImageName = imageName;
			this.Tooltip = tooltip;
			this.PanelName = panelName;
		}

		public CommandInfos(CommandInfos infos)
		{
			this.CmdName = infos.CmdName;
			this.CmdText = infos.CmdText;
			this.DllName = infos.DllName;
			this.ClassName = infos.ClassName;
			this.ImageName = infos.ImageName;
			this.Tooltip = infos.Tooltip;
			this.PanelName = infos.PanelName;
		}

		public static System.Windows.Controls.Image GetImageByName(string imageFillName)
		{
			System.Windows.Controls.Image result;
			try
			{
				if (!File.Exists(imageFillName))
				{
					imageFillName = FileUtility.GetAppRootPath() + "\\Res\\HcHelp16.png";
				}
				System.Windows.Controls.Image image = new System.Windows.Controls.Image();
				Bitmap bmp = new Bitmap(imageFillName);
				image.Source = CommandInfos.ChangeBitmapToBitmapSource(bmp);
				image.HorizontalAlignment = HorizontalAlignment.Left;
				image.Margin = new Thickness(0.0, 5.0, 0.0, 0.0);
				result = image;
			}
			catch (Exception)
			{
				MessageBox.Show("竖向菜单资源'" + imageFillName + "'不存在");
				result = null;
			}
			return result;
		}

		private static BitmapSource ChangeBitmapToBitmapSource(Bitmap bmp)
		{
			BitmapSource result;
			try
			{
				result = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
			}
			catch
			{
				result = null;
			}
			return result;
		}
	}
}
